<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title><{:C('web_site_name')}>---新闻管理</title>
    <link rel="stylesheet" type="text/css" href="<?php echo APP_TMPL_PATH ; ?>/static/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="<?php echo APP_TMPL_PATH ; ?>/static/css/main.css"/>

    <script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/jquery.js"></script>
    <script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/layer/lib.js"></script>
<script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/layer/layer.min.js"></script>
</head>
<body>
<div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i>首页<span class="crumb-step">&gt;</span><span class="crumb-name">后台新闻咨询管理</span></div>
        </div>
        <div class="search-wrap">
            <div class="search-content">
                <form action="#" method="post">
                    <table class="search-tab">
                        <tr>
                           <th width="70">栏目:</th>
                           <td>
                               <select   id="typeid" >
                               <option value="0">请选择</option>
        <?php 
       
            if(isset($category) && $category){
                foreach($category as $c_key => $c_v){   
            
        ?>
        <option value="<?php echo $c_v['id'] ;?>" <?php if($typeid == $c_v['id'] ){echo "selected";}?>><?php echo $c_v['html'];?><?php echo $c_v['typename']  ; ?></option>
        <?php 
            }
        }   
        ?>
        </select>

                           </td>
                            <th width="70">标题:</th>
                            <td><input class="common-text" placeholder="标题" name="title" value="" id="" type="text"></td>
                            
                           	<th width="70">资讯属性:</th>
                           	<td>
                             <select name="flag" style="width:90px">
                             <option value="">请选择</option>
							<?php 
								
									foreach(C("content_att") as $k_=>$v_){
					
								?>
				<option value="<?php echo $k_;?>" ><?php echo $v_;?></option>
						<?php 
								}	
									
						?>
	</select>
                                </td>
                                <th width="70">状态:</th>
                                <td>
                             <select name="status" style="width:90px">
                                <option value="all">请选择</option>
                                <option value="1">开启</option>
                                <option value="0">关闭</option>  
                            </select>
                                </td>
                            <td><input class="btn btn-primary btn2" name="sub" value="查询" type="button" onclick="search()"></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
        <div class="result-wrap">
            <form name="myform" id="myform" method="post">
                <div class="result-title">
                    <div class="result-list">
                        <a href="javascript:void(0)" onclick="add()"><i class="icon-font"></i>新增咨询</a>
                    </div>
                </div>
                 <div class="list-page" id="page_string"> 2 条 1/1 页</div>
                <div class="result-content">
                    <table class="result-tab" width="100%" >
                        <tr>
                            <th>编号</th>
                            <th>标题</th>
                            <th>分类</th>
                            <th>缩略图</th>
                            <th>pc图</th>
                            <th>wap图</th>
                            <th>关键词</th>
                            <th>添加日期 </th>
                            <th>修改日期 </th>
                            <th>权重</th>
                            <th>状态</th>
                            <th>发布者</th>
                            <th>点击数</th>
                       
                            <th>操作</th>
                        </tr>
                      <tbody id="result_"></tbody>
                        
                    </table>
                    
                    	
                    <div class="list-page" id="page_string"> 2 条 1/1 页</div>
                </div>
            </form>
        </div>
</body>
</html>
<script>
var loadding_0  ;
var page = 1 ;
$(function () {
	common_request();
});
function common_request(){
	var url="<?php echo U("news/index");?>&inajax=1";
	var data_ = {
		'page':page,
		'time':<?php echo time();?>,
		'action':'ajax_data' , 
		'title':$("input[name='title']").val() , 
		'flag':$("select[name='flag']").val() , 
        'status':$("select[name='status']").val() ,
        'typeid':$("#typeid").val() 
	} ;
	//console.dir(data_);
	$.ajax({
	type: "POST",
	url: url ,
	data: data_,
	cache:false,
	dataType:"json",
	// async:false,
	success: function(msg){
		var shtml = '' ;
		var list = msg.resultinfo.list;
		
		if(msg.resultcode!= 1 ){
			layer.msg(msg.resultinfo.errmsg);
			return false ;
		}else{
		
			for(var i in list){
				shtml+='<tr>';
				shtml+= '<td>'+list[i].id+'</td>' ;
				shtml+='<td>'+list[i]['title']+'</td>';
                shtml+='<td>'+list[i]['typename']+'</td>';
                shtml+='<td>'+list[i]['image']+'</td>';
                shtml+='<td>'+list[i]['pc_image']+'</td>';
                shtml+='<td>'+list[i]['wap_image']+'</td>';
				shtml+='<td >'+list[i]['keysword']+'</td>';
				shtml+='<td>'+list[i]['create_date']+'</td>';
				shtml+='<td>'+list[i]['modify_date']+'</td>';
				shtml+='<td>'+list[i]['weight']+'</td>';
				shtml+='<td>'+list[i]['status']+'</td>';
				shtml+='<td>'+list[i]['addperson']+'</td>';
				shtml+='<td>'+list[i]['click']+'</td>';
				shtml+='<td> <a href="javascript:void(0)" onclick="edit('+list[i].id+',this)" class="tablelink">修改</a>&nbsp;&nbsp;<a href="javascript:void(0)" onclick="del('+list[i].id+',this)" class="tablelink">删除</a></td>';
				shtml+='</tr>';
			}
			$("#result_").html(shtml);
			$(".list-page").html(msg.resultinfo.obj);
		}
		layer.close(loadding_0);
	},
	beforeSend:function(){
		 loadding_0 = layer.load('数据正在加载中。。。。。。'); 
	},
	error:function(){
		layer.msg('服务器繁忙请稍后');
		return false ;
	}
	});
}
function ajax_data(p){
	page = p  ; 
	common_request();
}
function search(){
	page = 1 ;
	common_request();
}
var _add = '' ;
//添加新闻咨询
function add(){
	_add = $.layer({
	    type: 2,
	    shadeClose: true,
	    title: "添加新闻咨询",
	    closeBtn: [0, true],
	    shade: [0.8, '#000'],
	    border: [1],
	    offset: ['20px',''],
	    area: ['90%','700px'],
        fix:false,
	    iframe: {src: "<?php echo U("news/add");?>&showpage=1"}
	}); 
}
var _edit = '' ;
//添加新闻咨询
function edit(id , o ){
    _edit = $.layer({
        type: 2,
        shadeClose: true,
        title: "修改新闻",
        closeBtn: [0, true],
        shade: [0.8, '#000'],
        border: [1],
        offset: ['20px',''],
        area: ['90%','700px'],
        fix:false,
        iframe: {src: "<?php echo U("news/edit");?>&showpage=1&id="+id}
    }); 
}
//关闭窗口
function close_add_div(){
	layer.close(_add);
}
//关闭窗口
function close_edit_div(){
    layer.close(_edit);
}
//编辑状态
function editStatus (id , status ){
    $.ajax({
    type: "POST",
    url: "<{:U('news/edit')}>&action=doStatus" ,
    data: {id:id , status:status},
    cache:false,
    dataType:"json",
    async:true,
    success: function(msg){
        var shtml = '' ;
        var list = msg.resultinfo.list;
        
        if(msg.resultcode!= 1 ){
            layer.msg(msg.resultinfo.errmsg);
           
        }else{
            
        }
        layer.close(loadding_0);
    },
    beforeSend:function(){
         loadding_0 = layer.load('数据正在处理中。。。。。。'); 
    },
    error:function(){
        layer.msg('服务器繁忙请稍后');
        return false ;
    }
    });
}
function del(id , o ){
    $.layer({
        shade: [0.8, '#000'],
        area: ['240px','auto'],
        shift: 'left', //从左动画弹出
        dialog: {
            msg: '确定删除数据吗？此操作不可恢复!',
            btns: 2,                    
            type: 4,
            btn: ['确定','取消'],
            yes: function(){
                $.ajax({
                       type: "POST",
                       url: "<?php echo U('news/del');?>" ,
                       data: {"id":id},
                       cache:false,
                       dataType:"json",
                       async:true,
                       success: function(msg){
                           if(msg.resultcode != 1){
                              layer.msg(msg.resultinfo.errmsg);
                             return false ; 
                            }else{
                                common_request();
                            }
                            layer.close(loadding_0);
                       },
                       beforeSend:function(){
                              var loadding_0 = layer.load('数据处理中....'); 
                       },
                       error:function(){
                               loadding_1 = layer.load('服务器繁忙请稍后等待。。。。。。'); 
                       }
                      
                    }); 
                //layer.msg('重要', 1, 1);
            }, no: function(){
                
            }
        }
    });
}
</script> 

